function wnd(content,modal,width,height){
	this.object = null;
	this.content = content || '';
	this.width = width || null;
	this.height = height || null;
	this.blackscreen = null;
	this.modal = modal || false;
	this.posX = 0;
	this.posY = 0;
	this.relObj = null;
	this.relDest = null;
	this.shiftX = null;
	this.shiftY = null;
	var self=this;
	
	this.setContent = function(content,speed){
		speed=speed || 0;
		this.content=content;
		if(this.object!=null){
			$(this.object).html(this.content);
			this.move(speed);
		}
	}

	this.getContent = function(){
		return this.content;
	}

	this.setZindex = function(zIndex){
		$(this.object).css('z-index',zIndex);
		if(modal){$(this.blackscreen).css('z-index',zIndex-1);}
	}

	this.setSize = function(width,height){
		if(width){
			this.width=width;
			this.object.css('width',width+'px')
		}
		if(height){
			this.height=height;
			this.object.css('height',height+'px')
		}
	}

	this.moveXY = function(speed){
		speed=speed || 0;
		if(this.object!=null){
			$(this.object).css({'left':this.posX+'px','top':this.posY+'px'});
		}
	}

	this.move = function(speed){
		if(this.relObj){
			this.relMove();
			this.moveXY(speed);
		}else{
			this.moveXY(speed);
		}
	}

	this.setPositionXY = function(x,y){
		if(x!=null){this.posX=x;}
		if(y!=null){this.posY=y;}
		this.relObj = null;
		this.move();
	}
	
	this.moveUpDown = function(y){
		this.posY=this.posY+y;
		this.moveXY();
	}

	this.moveLeftRight = function(y){
		this.posX=this.posX+x;
		this.moveXY();
	}

	this.setRelativePosition = function(rel,shiftX,shiftY,obj){
		this.relObj=obj || $(window);
		this.shiftX=shiftX || 0;
		this.shiftY=shiftY || 0;
		this.relDest=rel;
		this.move();
	}

	this.relMove = function(){
		if(this.shiftX=='+'){this.shiftX=($(this.object).outerWidth());}
		if(this.shiftX=='-'){this.shiftX=-($(this.object).outerHeight());}
		if(this.shiftY=='+'){this.shiftY=($(this.object).outerWidth());}
		if(this.shiftY=='-'){this.shiftY=-($(this.object).outerHeight());}
		if(this.relObj.offset()){
			lft=this.relObj.offset().left;
			tp=this.relObj.offset().top;
		}else{
			lft=0;
			tp=0;
		}
		if(this.relDest=='center'){
			this.posX=(lft)+(this.relObj.width() / 2)-($(this.object).outerWidth() / 2)+(this.relObj.scrollLeft() || 0)+this.shiftX;
			this.posY=(tp)+(this.relObj.height() / 2)-($(this.object).height() / 2)+(this.relObj.scrollTop() || 0)+this.shiftY;
		}
		if(this.relDest=='bottom'){
			this.posX=(lft)+(this.relObj.width() / 2)-($(this.object).outerWidth() / 2)+(this.relObj.scrollLeft() || 0)+this.shiftX;
			this.posY=(tp)+(this.relObj.height())+(this.relObj.scrollTop() || 0)+this.shiftY;
		}
		if(this.relDest=='top'){
			this.posX=(lft)+(this.relObj.width() / 2)-($(this.object).outerWidth() / 2)+(this.relObj.scrollLeft() || 0)+this.shiftX;
			this.posY=(tp)+(this.relObj.scrollTop() || 0)+this.shiftY;
		}
		if(this.relDest=='left'){
			this.posX=(lft)-($(this.object).outerWidth())+this.shiftX;
			this.posY=(tp)+(this.relObj.height() / 2)-($(this.object).height() / 2)+(this.relObj.scrollTop() || 0)+this.shiftY;
		}
		if(this.relDest=='right'){
			this.posX=(lft)+(this.relObj.width())+this.shiftX;
			this.posY=(tp)+(this.relObj.height() / 2)-($(this.object).height() / 2)+(this.relObj.scrollTop() || 0)+this.shiftY;
		}
		
	}

	this.ajaxLoad = function(addr,post,action,json){
		action = action || null;
		post = post || '';
		json = json || false;
		self.setContent('<div style="padding:20px;"><img src="/static/css/preload.gif" alt="" /></div>');
		$.ajax({
			type: "POST",
			url: addr,
			data: post,
			success: function(data){
				if(!json)
					self.setContent(data,300);

				if(action!=null)
					action(data);

				self.move();
			}
		});
	}
	
	this.close = function(){
		$(self.object).fadeOut(300, function(){
			$(self.object).remove();
			
		});
		$(self.blackscreen).fadeOut(200, function(){
			$(self.blackscreen).remove();
		})
		//$(self.blackscreen).fadeOut(200, function(){});
	}
	this.draw = function(){
		this.object=$('<div class="mywnd">'+this.content+'</div>').appendTo('body');
		this.setSize(this.width,this.height);
		$(this.object).bind('click',function(e){
			if($(e.target).hasClass('closeMywnd')){self.close();}
		})
		if(this.modal){this.blackscreen=$('<div class="blackscreen"></div>').appendTo('body');}
	}
	this.draw();
}